<form action="{{$base_index_url}}/acl/admin/groups/" method="post" name="module_permission">
<input type="hidden" name="ui_tab_index" value="3"/>
    <h4>Select Group:</h4>
    <select id="select_group" name="select_group" class="long" onchange="document.forms.module_permission.submit();">
        <option></option>
        {{foreach from=$groups item=group}}
        {{if $selected_group_id==$group->id}}
        {{assign var=selected_desc value=$group->description}}
        {{/if}}
        <option value="{{$group->id}}" {{if $selected_group_id==$group->id}}selected{{/if}}>
                {{$group->name}}
    </option>
    {{/foreach}}
</select>
{{if isset($selected_desc)}}
<span style="color:gray;font-size: 9px">{{$selected_desc}}</span>
{{/if}}

</form>
<br/>
<h4>Module Permissions for selected group:</h4>

<table id="table" width="100%" >
    <thead>
        <tr>
            <th>Module Name</th>
            <th>Description</th>
            <th>Has Permission</th>
        </tr>
    </thead>
    <tbody>
        {{if  $selected_group_id<>""}}
            {{foreach from=$modules item=module}}
            <tr  {{if $module->has_permission=="1"}} class='table_row selected' {{else}} class="table_row" {{/if}}>
                <td>
                    {{$module->friendly_name}}
                </td>
                <td>
                    {{$module->description}}
                </td>
                <td>

                    <input type="checkbox" onclick="toogle_permission(this,'{{$module->id}}')" {{if $module->has_permission=="1"}}checked{{/if}}  />
                </td>

            </tr>

            {{/foreach}}
        {{else}}
            
        {{/if}}
    </tbody>
</table>

<script type="text/javascript">
    function toogle_permission(self,module_name){
        var group_id =  '{{$selected_group_id}}';
        var flag = self.checked?"1":"0";
        if(group_id && group_id.length){
            $.ajax({
                type:"POST",
                dataType:'text',
                data:"is_ajax=1&group_id="+group_id+"&module_name="+module_name+"&flag="+ flag,
                url: module_admin_url+"/groups/toggle_module_permission",
                beforeSend :function(){
                    $.blockUI("<h1>Please wait...</h1>");
                },
                complete :  function(data){
                    $.unblockUI();
                }
            });
        }
    }
</script>
